<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Create rollup jobs API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'rollup-put-job.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/rollup-put-job.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/rollup-put-job.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/rollup-put-job.html" rel="nofollow" target="_blank">../en/rollup-put-job.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="rollup-apis.html">Rollup APIs</a></span>
»
<span class="breadcrumb-node">Create rollup jobs API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="rollup-apis.html">« Rollup APIs</a>
</span>
<span class="next">
<a href="rollup-delete-job.html">Delete rollup jobs API »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="rollup-put-job"></a>Create rollup jobs API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rollup/apis/put-job.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>

<p>Creates a rollup job.</p>
<div class="warning admon">
<div class="icon"></div>
<div class="admon_content">
<p>This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollup-put-job-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rollup/apis/put-job.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">PUT _rollup/job/&lt;job_id&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollup-put-job-api-prereqs"></a>Prerequisites<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rollup/apis/put-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
If the Elasticsearch security features are enabled, you must have <code class="literal">manage</code> or
<code class="literal">manage_rollup</code> cluster privileges to use this API. For more information, see
<a class="xref" href="security-privileges.html" title="Security privileges">Security privileges</a>.
</li>
</ul>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollup-put-job-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rollup/apis/put-job.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The rollup job configuration contains all the details about how the job should
run, when it indexes documents, and what future queries will be able to execute
against the rollup index.</p>
<p>There are three main sections to the job configuration: the logistical details
about the job (cron schedule, etc), the fields that are used for grouping, and
what metrics to collect for each group.</p>
<p>Jobs are created in a <code class="literal">STOPPED</code> state. You can start them with the
<a class="xref" href="rollup-start-job.html" title="Start rollup jobs API">start rollup jobs API</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollup-put-job-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rollup/apis/put-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;job_id&gt;</code>
</span>
</dt>
<dd>
(Required, string) Identifier for the rollup job. This can be any
alphanumeric string and uniquely identifies the data that is associated with
the rollup job. The ID is persistent; it is stored with the rolled up data.
If you create a job, let it run for a while, then delete the job, the data
that the job rolled up is still be associated with this job ID. You cannot
create a new job with the same ID since that could lead to problems with
mismatched job configurations.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollup-put-job-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rollup/apis/put-job.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">cron</code>
</span>
</dt>
<dd>
(Required, string) A cron string which defines the intervals when the
rollup job should be executed. When the interval triggers, the indexer
attempts to rollup the data in the index pattern. The cron pattern is
unrelated to the time interval of the data being rolled up. For example, you
may wish to create hourly rollups of your document but to only run the indexer
on a daily basis at midnight, as defined by the cron. The cron pattern is
defined just like a Watcher cron schedule.
</dd>
</dl>
</div>
<div class="variablelist">
<a id="rollup-groups-config"></a>
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">groups</code>
</span>
</dt>
<dd>
<p>
(Required, object) Defines the grouping fields and aggregations that are
defined for this rollup job. These fields will then be available later for
aggregating into buckets.
</p>
<p>These aggs and fields can be used in any combination. Think of the <code class="literal">groups</code>
configuration as defining a set of tools that can later be used in aggregations
to partition the data. Unlike raw data, we have to think ahead to which fields
and aggregations might be used. Rollups provide enough flexibility that you
simply need to determine <em>which</em> fields are needed, not <em>in what order</em> they are
needed.</p>
<p>There are three types of groupings currently available:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">date_histogram</code>
</span>
</dt>
<dd>
<p>
(Required, object) A date histogram group aggregates a <code class="literal">date</code> field into
time-based buckets. This group is <span class="strong strong"><strong>mandatory</strong></span>; you currently cannot rollup
documents without a timestamp and a <code class="literal">date_histogram</code> group. The
<code class="literal">date_histogram</code> group has several parameters:
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">field</code>
</span>
</dt>
<dd>
(Required, string) The date field that is to be rolled up.
</dd>
<dt>
<span class="term">
<code class="literal">calendar_interval</code> or <code class="literal">fixed_interval</code>
</span>
</dt>
<dd>
<p>
(Required, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) The interval of time buckets to be
generated when rolling up. For example, <code class="literal">60m</code> produces 60 minute (hourly)
rollups. This follows standard time formatting syntax as used elsewhere in
Elasticsearch. The interval defines the <em>minimum</em> interval that can be aggregated only.
If hourly (<code class="literal">60m</code>) intervals are configured, <a class="xref" href="rollup-search.html" title="Rollup search">rollup search</a>
can execute aggregations with 60m or greater (weekly, monthly, etc) intervals.
So define the interval as the smallest unit that you wish to later query. For
more information about the difference between calendar and fixed time
intervals, see <a class="xref" href="rollup-understanding-groups.html#rollup-understanding-group-intervals" title="Calendar vs fixed time intervals">Calendar vs fixed time intervals</a>.
</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Smaller, more granular intervals take up proportionally more space.</p>
</div>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">delay</code>
</span>
</dt>
<dd>
<p>
(Optional,<a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) How long to wait before rolling up new
documents. By default, the indexer attempts to roll up all data that is
available. However, it is not uncommon for data to arrive out of order,
sometimes even a few days late. The indexer is unable to deal with data that
arrives after a time-span has been rolled up. That is to say, there is no
provision to update already-existing rollups.
</p>
<p>Instead, you should specify a <code class="literal">delay</code> that matches the longest period of time
you expect out-of-order data to arrive. For example, a <code class="literal">delay</code> of <code class="literal">1d</code>
instructs the indexer to roll up documents up to <code class="literal">now - 1d</code>, which provides
a day of buffer time for out-of-order documents to arrive.</p>
</dd>
<dt>
<span class="term">
<code class="literal">time_zone</code>
</span>
</dt>
<dd>
(Optional, string) Defines what time_zone the rollup documents are stored as.
Unlike raw data, which can shift timezones on the fly, rolled documents have
to be stored with a specific timezone. By default, rollup documents are stored
in <code class="literal">UTC</code>.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">terms</code>
</span>
</dt>
<dd>
<p>
(Optional, object) The terms group can be used on <code class="literal">keyword</code> or numeric fields
to allow bucketing via the <code class="literal">terms</code> aggregation at a later point. The indexer
enumerates and stores <em>all</em> values of a field for each time-period. This can
be potentially costly for high-cardinality groups such as IP addresses,
especially if the time-bucket is particularly sparse.
</p>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>While it is unlikely that a rollup will ever be larger in size than the raw
data, defining <code class="literal">terms</code> groups on multiple high-cardinality fields can
effectively reduce the compression of a rollup to a large extent. You should be
judicious which high-cardinality fields are included for that reason.</p>
</div>
</div>
<p>The <code class="literal">terms</code> group has a single parameter:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">fields</code>
</span>
</dt>
<dd>
(Required, string) The set of fields that you wish to collect terms for. This
array can contain fields that are both <code class="literal">keyword</code> and numerics. Order does not
matter.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">histogram</code>
</span>
</dt>
<dd>
<p>
(Optional, object) The histogram group aggregates one or more numeric fields
into numeric histogram intervals.
</p>
<p>The <code class="literal">histogram</code> group has a two parameters:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">fields</code>
</span>
</dt>
<dd>
(Required, array) The set of fields that you wish to build histograms for. All fields
specified must be some kind of numeric.  Order does not matter.
</dd>
<dt>
<span class="term">
<code class="literal">interval</code>
</span>
</dt>
<dd>
(Required, integer) The interval of histogram buckets to be generated when
rolling up. For example, a value of <code class="literal">5</code> creates buckets that are five units
wide (<code class="literal">0-5</code>, <code class="literal">5-10</code>, etc). Note that only one interval can be specified in the
<code class="literal">histogram</code> group, meaning that all fields being grouped via the histogram
must share the same interval.
</dd>
</dl>
</div>
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">index_pattern</code>
</span>
</dt>
<dd>
<p>
(Required, string) The index or index pattern to roll up. Supports
wildcard-style patterns (<code class="literal">logstash-*</code>). The job will
attempt to rollup the entire index or index-pattern.
</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The <code class="literal">index_pattern</code> cannot be a pattern that would also match the
destination <code class="literal">rollup_index</code>. For example, the pattern <code class="literal">foo-*</code> would match the
rollup index <code class="literal">foo-rollup</code>. This situation would cause problems because the
rollup job would attempt to rollup its own data at runtime. If you attempt to
configure a pattern that matches the <code class="literal">rollup_index</code>, an exception occurs to
prevent this behavior.</p>
</div>
</div>
</dd>
</dl>
</div>
<div class="variablelist">
<a id="rollup-metrics-config"></a>
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">metrics</code>
</span>
</dt>
<dd>
<p>
(Optional, object) Defines the metrics to collect for each grouping tuple.
By default, only the doc_counts are collected for each group. To make rollup
useful, you will often add metrics like averages, mins, maxes, etc. Metrics
are defined on a per-field basis and for each field you configure which metric
should be collected.
</p>
<p>The <code class="literal">metrics</code> configuration accepts an array of objects, where each object has
two parameters:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">field</code>
</span>
</dt>
<dd>
(Required, string) The field to collect metrics for. This must be a numeric
of some kind.
</dd>
<dt>
<span class="term">
<code class="literal">metrics</code>
</span>
</dt>
<dd>
(Required, array) An array of metrics to collect for the field. At least one
metric must be configured. Acceptable metrics are <code class="literal">min</code>,<code class="literal">max</code>,<code class="literal">sum</code>,<code class="literal">avg</code>, and
<code class="literal">value_count</code>.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">page_size</code>
</span>
</dt>
<dd>
(Required, integer) The number of bucket results that are processed on each
iteration of the rollup indexer. A larger value tends to execute faster, but
requires more memory during processing. This value has no effect on how the
data is rolled up; it is merely used for tweaking the speed or memory cost of
the indexer.
</dd>
<dt>
<span class="term">
<code class="literal">rollup_index</code>
</span>
</dt>
<dd>
(Required, string) The index that contains the rollup results. The index can
be shared with other rollup jobs. The data is stored so that it doesn’t
interfere with unrelated jobs.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollup-put-job-api-example"></a>Example<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rollup/apis/put-job.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The following example creates a rollup job named <code class="literal">sensor</code>, targeting the
<code class="literal">sensor-*</code> index pattern:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _rollup/job/sensor
{
    "index_pattern": "sensor-*",
    "rollup_index": "sensor_rollup",
    "cron": "*/30 * * * * ?",
    "page_size" :1000,
    "groups" : { <a id="CO602-1"></a><i class="conum" data-value="1"></i>
      "date_histogram": {
        "field": "timestamp",
        "fixed_interval": "1h",
        "delay": "7d"
      },
      "terms": {
        "fields": ["node"]
      }
    },
    "metrics": [ <a id="CO602-2"></a><i class="conum" data-value="2"></i>
        {
            "field": "temperature",
            "metrics": ["min", "max", "sum"]
        },
        {
            "field": "voltage",
            "metrics": ["avg"]
        }
    ]
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1868.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO602-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>This configuration enables date histograms to be used on the <code class="literal">timestamp</code>
field and <code class="literal">terms</code> aggregations to be used on the <code class="literal">node</code> field.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO602-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>This configuration defines metrics over two fields: <code class="literal">temperature</code> and
<code class="literal">voltage</code>. For the <code class="literal">temperature</code> field, we are collecting the min, max, and
sum of the temperature. For <code class="literal">voltage</code>, we are collecting the average.</p>
</td>
</tr>
</table>
</div>
<p>When the job is created, you receive the following results:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "acknowledged": true
}</pre>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="rollup-apis.html">« Rollup APIs</a>
</span>
<span class="next">
<a href="rollup-delete-job.html">Delete rollup jobs API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>